package precision;

/**
 * Integer representation on a FPObj
 * @author Richard J. Inskip, Benjamin T. Jones
 *
 */

public class Ints implements FPObj {

	private int a;
	
	public Ints(){
		this.a = 0;
	}
	
	public Ints(int a){
		this.a = a;
	}
	
	/**
	 * Ensure both objects are of the same class
	 * @param b FPObj to test <cod>this</code> against
	 */
	private void checkClass(FPObj b)
	{
		if ( this.getClass() != b.getClass() )
		{
			throw new RuntimeException("Mismatched FPObj types; was expecting " + this.getClass() +
					" and recieved " + b.getClass()+ ".");
		}
	}
	
	public int getValue(){
		return this.a;
	}
	
	@Override
	public FPObj add(FPObj b) {
		checkClass(b);
		return new Ints(a + ((Ints)b).getValue());
	}

	@Override
	public FPObj divide(FPObj b) {
		checkClass(b);
		return new Ints(a / ((Ints)b).getValue());
	}

	@Override
	public FPObj multi(FPObj b) {
		checkClass(b);
		return new Ints(a * ((Ints)b).getValue());
	}
	
	@Override
	public boolean greaterThan(FPObj b){
		checkClass(b);
		boolean test=false;
		if(this.getValue()>((Ints)b).getValue()){
			test=true;
		}
		return test;
	}

	@Override
	public FPObj sub(FPObj b) {
		checkClass(b);
		return new Ints(a - ((Ints)b).getValue());
	}

	@Override
	public float toFloat() {
		return (int)a;
	}
	
	public String toString(){
		return (""+a);
	}

	@Override
	public FPObj newFPObj() {
		return new Ints();
	}
	
	@Override
	public FPObj newFPObj(int a) {
		return new Ints((int)a);
	}

	@Override
	public FPObj abs() {
		return new Ints(Math.abs(a));
	}
	
	@Override
	public String toType(){
		return "Integer";
	}
	
}
